package com.lmb.controller;

import com.lmb.bean.Houses;
import com.lmb.mapper.HousesDao;
import com.lmb.service.HousesService;
import com.lmb.util.Page;
import com.lmb.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin //允许跨域访问
@RequestMapping("/houses")
public class HousesController {
    @Autowired
    HousesDao housesDao;
    @Autowired
    HousesService housesService;
    @PostMapping
    public Result add(@RequestBody Houses houses)
    {
        Object obj=housesService.add(houses);
        return Result.success(obj);
    }
    @DeleteMapping("{id}")
    public Result del(@PathVariable("id") Integer id){
        Object obj=housesService.del(id);
        return Result.success(obj);
    }
    @PutMapping
    public Result edit(@RequestBody Houses houses){
        Object obj=housesService.edit(houses);
        return Result.success(obj);
    }
    @GetMapping("all")
    public Result all( Houses houses){
        Object obj=housesService.all(houses);
        return Result.success(obj);
    }
    @GetMapping("{id}")
    public Result one(@PathVariable("id") Integer id){
        Object obj=housesService.one(id);
        return Result.success(obj);
    }
    @GetMapping("page")
    public Result page(Page page, Houses houses){
        housesService.page(page,houses);
        return Result.success(page);
    }
}
